﻿using System.Linq;
using Journal.Domain.IDomainServices;
using Journal.Domain.Models;
using Journal.Domain.RepositoryInterfaces;

namespace Journal.Domain.DomainServices
{
    public class EducationInstitutionDomainService : BaseDomainService<EducationInstitution>, IEducationInstitutionDomainService
    {
        public EducationInstitutionDomainService(IEducationInstitutionRepository repository)
            : base(repository)
        {
        }

        public EducationInstitution GetEducationInstitution(int id)
        {
            var s = (IEducationInstitutionRepository) Repository;
            s.Test();
            return new EducationInstitution();
        }

        public int GetEducationInstitutionIdByUserId(int userId)
        {
            EducationInstitution educationInstitution = Repository.Query().SingleOrDefault(x => x.Director.Id == userId);
            if (educationInstitution == null)
            {
                return 0;
            }

            return educationInstitution.Id;
        }
    }
}